package name.jiaosha.air.system.controller;

import java.util.ArrayList;
import java.util.List;

import name.jiaosha.air.AppConstants;
import name.jiaosha.air.system.domain.Area;
import name.jiaosha.air.system.service.IAreaService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * 地区控制器
 * 
 * @author xu
 * 
 */
@Controller
@RequestMapping("/admin/area")
public class AreaController {

	@Autowired
	private IAreaService areaService;
	
	@RequestMapping("/province")
	public ModelAndView getProvince() throws Exception {

		List<Area> list = null;

		if (AppConstants.DEBUG) {
			list = new ArrayList<Area>();
			Area area = new Area();
			area.setId(1);
			area.setProvince("浙江省");
			list.add(area);

		} else {

		}

		ModelMap model = new ModelMap();
		model.addAttribute("root", list);
		return new ModelAndView("jsonView", model);
	}

	@RequestMapping("/city")
	public ModelAndView getCity() throws Exception {

		List<Area> list = null;

		if (AppConstants.DEBUG) {
			list = new ArrayList<Area>();
			Area area = new Area();
			area.setId(1);
			area.setProvince("浙江省");
			area.setCity("杭州市");
			list.add(area);

		} else {

		}

		ModelMap model = new ModelMap();
		model.addAttribute("root", list);
		return new ModelAndView("jsonView", model);
	}

	@RequestMapping("/district")
	public ModelAndView getDistrict() throws Exception {

		List<Area> list = null;

		if (!AppConstants.DEBUG) {
			list = new ArrayList<Area>();
			Area area = new Area();
			area.setId(1);
			area.setProvince("浙江省");
			area.setCity("杭州市");
			area.setDistrict("西湖区");
			list.add(area);

			area = new Area();
			area.setId(2);
			area.setProvince("浙江省");
			area.setCity("杭州市");
			area.setDistrict("上城区");
			list.add(area);
			
			area = new Area();
			area.setId(3);
			area.setProvince("浙江省");
			area.setCity("杭州市");
			area.setDistrict("下城区");
			list.add(area);

		} else {
         
			list=areaService.getDistrictByCityId(953);
		}

		ModelMap model = new ModelMap();
		model.addAttribute("root", list);
		return new ModelAndView("jsonView", model);
	}

}
